<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <style>
        .login-button {
            border-radius: 30px;
            width: 100px;
            margin: 20px auto;
            color: white;
            background-color: blue;
            text-align: center;
            padding: 10px 0;
            cursor: pointer;
        }
        .hidden {
            display: none;
        }
    </style>
</head>
<body>
    <div id="Application" style="text-align: center;">
        <h1 id="title">欢迎您:未登录</h1>
        <div id="loginForm">
            <div>
                <label for="userName">账号:</label>
                <input id="userName" type="text" />
            </div>
            <div>
                <label for="password">密码:</label>
                <input id="password" type="password" />
            </div>
        </div>
        <div id="loginButton" class="login-button">登录</div>
    </div>

    <script>
        // 获取DOM元素
        const titleElement = document.getElementById('title');
        const loginFormElement = document.getElementById('loginForm');
        const loginButtonElement = document.getElementById('loginButton');
        const userNameElement = document.getElementById('userName');
        const passwordElement = document.getElementById('password');

        // 状态变量
        let isLoggedIn = false;

        // 添加点击事件监听器
        loginButtonElement.addEventListener('click', function() {
            if (!isLoggedIn) {
                login();
            } else {
                logout();
            }
        });

        // 登录函数
        function login() {
            const userName = userNameElement.value;
            const password = passwordElement.value;
            
            if (userName.length > 0 && password.length > 0) {
                alert(`userName: ${userName} password: ${password}`);
                isLoggedIn = true;
                titleElement.textContent = `欢迎您: ${userName}`;
                loginButtonElement.textContent = "注销";
                loginFormElement.classList.add('hidden');
                userNameElement.value = "";
                passwordElement.value = "";
            } else {
                alert("请输入账号密码");
            }
        }

        // 注销函数
        function logout() {
            isLoggedIn = false;
            titleElement.textContent = "欢迎您:未登录";
            loginButtonElement.textContent = "登录";
            loginFormElement.classList.remove('hidden');
        }
    </script>
</body>
</html>
